package com.luanye.enjoy.controller;

import com.luanye.enjoy.entity.Tribe;
import com.luanye.enjoy.enums.ResultCode;
import com.luanye.enjoy.service.TribeService;
import com.luanye.enjoy.vo.RespBean;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;
import java.util.Objects;

@RestController
@RequestMapping("/tribe")
@AllArgsConstructor
public class TribeController {

    private final TribeService tribeService;

    @PostMapping("/create/{openid}")
    public RespBean create(@RequestBody Tribe tribe, @PathVariable("openid") String openid){
        if (Objects.isNull(tribe.getTrideName()) || Objects.isNull(tribe.getBrief()) || Objects.isNull(tribe.getLocation()))
            return RespBean.error(ResultCode.VALIDATE_ERROR);
        return tribeService.createTribe(tribe,openid);
    }

    @GetMapping("/getAllByNum")
    public RespBean getAllByNum(){
        return tribeService.getAllByNum();
    }

    @GetMapping("/getDetail/{id}/{openid}")
    public RespBean getDetail(@PathVariable("id") Integer id,@PathVariable("openid") String openid){
        return tribeService.getDetail(id,openid);
    }
    @GetMapping("/join/{id}/{openid}")
    public RespBean joinTribe(@PathVariable("id") Integer id,@PathVariable("openid") String openid){
        return tribeService.joinTribe(id,openid);
    }
    @GetMapping("/exit/{id}/{openid}")
    public RespBean exitTribe(@PathVariable("id") Integer id,@PathVariable("openid") String openid){
        return tribeService.exitTribe(id,openid);
    }
    @GetMapping("/getAllMember/{id}")
    public RespBean getAllMember(@PathVariable("id") Integer id){
        return tribeService.getAllMember(id);
    }

    @GetMapping("/getMy/{openid}")
    public RespBean getMy(@PathVariable("openid") String openid){
        return tribeService.getMy(openid);
    }

    @GetMapping("/dissolve/{id}/{openid}")
    public RespBean dissolve(@PathVariable("id") Integer id,@PathVariable("openid") String openid){
        return tribeService.dissolve(id,openid);
    }

    @GetMapping("/getByUser/{openid}")
    public RespBean getByUser(@PathVariable("openid") String openid){
        return tribeService.getByUser(openid);
    }
}
